package leetcode.problems.P53最大子数组和;

public class MaxSubArray {
}

class Solution {
    public int maxSubArray(int[] nums) {
        int maxSum = Integer.MIN_VALUE, tmpSum = 0;
        for (int num : nums) {
            tmpSum += num;
            maxSum = Math.max(maxSum, tmpSum);
            if (tmpSum < 0) {
                tmpSum = 0;
            }
        }
        return maxSum;
    }
}